home *** CD-ROM | disk | FTP | other *** search
/ TOS Silver 2000 / TOS Silver 2000.iso / programm / GNU_C++ / LIB / CFLIB-11.LZH / demo / pdlg.c < prev   
Encoding:
C/C++ Source or Header  |  1998-11-07  |  6.4 KB  |  289 lines

  1. #include <cflib.h>
  2.  
  3. #ifdef __MTAES__
  4. #include <prdialog.h>
  5. #include <prsettng.h>
  6. #define __CDECL cdecl
  7. #else
  8. #include <gemx.h>
  9. #endif
  10.  
  11. #include    "demo.h"
  12.  
  13. /* Event-Routine der MDials */
  14. extern void handle_mdial_msg(int *msg);
  15.  
  16. #ifndef FALSE
  17. #define FALSE    0
  18. #define TRUE    1
  19. #endif
  20.  
  21. extern OBJECT    *popups;
  22.     
  23. /*
  24.  * Callbacks für Sub-Dialog
  25. */
  26. long __CDECL init_qed_sub(PRN_SETTINGS *settings, PDLG_SUB *sub_dialog)
  27. {
  28.     OBJECT    *tree;
  29.     int        offset;
  30.  
  31.     tree = sub_dialog->tree;
  32.     offset = sub_dialog->index_offset;
  33.  
  34.     set_string(tree, PS_WPNAME + offset, "<unbekannt>");
  35.     set_int(tree, PS_WPSL + offset, 65);
  36.     set_int(tree, PS_WPZL + offset, 80);
  37.  
  38.     set_string(tree, PS_GFNAME + offset, "6x6 system font");
  39.     set_int(tree, PS_GFPTS + offset, 10);
  40.  
  41.     return 1;
  42. }
  43.  
  44. #ifdef __MTAES__
  45. long __CDECL do_qed_sub(PRN_SETTINGS *settings, PDLG_SUB *sub_dialog, int exit_obj)
  46. #else
  47. long __CDECL do_qed_sub(PRN_SETTINGS *settings, PDLG_SUB *sub_dialog, short exit_obj)
  48. #endif
  49. {
  50.     OBJECT    *tree;
  51.     int        offset;
  52.     int        id = 1, pts = 10;
  53.  
  54.     tree = sub_dialog->tree;
  55.     offset = sub_dialog->index_offset;
  56.     switch (exit_obj - offset)
  57.     {
  58.         case PS_WPDSTR :
  59.         case PS_WPDPOP :
  60.             if ((exit_obj - offset) == PS_WPDPOP)
  61.                 handle_popup(tree, PS_WPDPOP + offset, popups, DICHTEPOP, POP_OPEN);
  62.             else
  63.                 handle_popup(tree, PS_WPDPOP + offset, popups, DICHTEPOP, POP_CYCLE);
  64.             break;
  65.  
  66.         case PS_WPSEL :
  67.             set_state(tree, exit_obj, SELECTED, FALSE);
  68.             redraw_obj(tree, exit_obj);
  69.             break;
  70.     
  71.         case PS_GFSEL :
  72.             do_fontsel((FS_M_XFSL|FS_M_MAGX), "Druckerfont wählen", &id, &pts);
  73.             set_state(tree, exit_obj, SELECTED, FALSE);
  74.             redraw_obj(tree, exit_obj);
  75.             break;
  76.     }
  77.     return 1;
  78. }
  79.  
  80. long __CDECL reset_qed_sub(PRN_SETTINGS *settings, PDLG_SUB *sub_dialog)
  81. {
  82. /*
  83.     OBJECT    *tree;
  84.     int        offset;
  85.  
  86.     tree = sub_dialog->tree;
  87.     offset = sub_dialog->index_offset;
  88. */
  89.     return 1;
  90. }
  91.  
  92.  
  93. PDLG_SUB    *create_sub_dialog(void)
  94. {
  95.     PDLG_SUB    *sub = NULL;
  96.     OBJECT    *tree;
  97.  
  98.     sub = malloc(sizeof(PDLG_SUB));
  99.     if (sub)
  100.     {
  101.         sub->next = 0L;
  102.         sub->option_flags = 0;
  103.         sub->sub_id = -1;
  104.  
  105.         rsrc_gaddr(R_TREE, PDLGICON, &tree);
  106.         sub->sub_icon = tree + PRN_ICON;        /* Zeiger auf das Icon */
  107.  
  108.         rsrc_gaddr(R_TREE, PRN_SUB, &tree);
  109.         sub->sub_tree = tree;                    /* Zeiger auf den Unterdialogs */
  110.  
  111.         sub->dialog = 0L;                            /* Zeiger auf die Struktur des Fensterdialogs oder 0L */
  112.         sub->tree = 0L;                            /* Zeiger auf den zusammengesetzen Objektbaum */
  113.         sub->index_offset = 0;                    /* Indexverschiebung des Unterdialogs */
  114.         sub->reserved1 = 0;
  115.         sub->reserved2 = 0;
  116.  
  117.         sub->init_dlg = init_qed_sub;            /* Initialisierungsfunktion */
  118.         sub->do_dlg = do_qed_sub;                /* Behandlungsfunktion */
  119.         sub->reset_dlg = reset_qed_sub;        /* Zurücksetzfunktion */
  120.         sub->reserved3 = 0;
  121.     }
  122.     return sub;
  123. }
  124.  
  125.  
  126. int wlfp_available( void )
  127. {
  128.     int    ag1, ag2, ag3, ag4;
  129.  
  130.     if (appl_xgetinfo(7, &ag1, &ag2, &ag3, &ag4))
  131.     {
  132.         if ((ag1 & 0x17 ) == 0x17)
  133.             return 1;
  134.     }
  135.     return 0;
  136. }
  137.  
  138. /* --------------------------------------------------------------------------- */
  139. static void save_settings(PRN_SETTINGS *settings)
  140. {
  141. /*
  142.     fd = fopen("i:\\pdlg.set", "wb");
  143.     if (fd)
  144.     {
  145.         fwrite(settings, 1, sizeof(PRN_SETTINGS), fd);
  146.         fclose(fd);
  147.     }
  148. */
  149. }
  150.  
  151. static PRN_SETTINGS *load_settings(PRN_DIALOG *prn_dialog)
  152. {
  153.     PRN_SETTINGS     *set = NULL;
  154.  
  155.     set = pdlg_new_settings(prn_dialog);
  156.     if (set)
  157.     {
  158. /*
  159.         fd = fopen("i:\\pdlg.set", "rb");
  160.         if (fd)
  161.         {
  162.             fread(set, 1, sizeof(PRN_SETTINGS), fd);
  163.             fclose(fd);
  164.         }
  165.         else
  166. */
  167.             pdlg_dflt_settings(prn_dialog, set);
  168.     }
  169.     return set;
  170. }
  171.  
  172. /* --------------------------------------------------------------------------- */
  173. void test_pdlg(int in_win)
  174. {
  175. #if defined(__GNUC__) && !defined(__MSHORT__)
  176.     do_alert(1, 0, "[3][pdlg und GNU geht nicht, da ich nicht|weiss, wie ich ohne -mshort eine 16bit|Parameterübergabe realisiere!][schade]");
  177.     return;
  178. #else
  179.     if (wlfp_available())
  180.     {
  181.         PRN_SETTINGS    *prn_settings;
  182.         PRN_DIALOG        *prn_dialog;
  183.         int                d, button, ret, handle;
  184.         EVNT                ev;
  185. #ifdef __MTAES__
  186.         MOBLK                n = {0,0,0,0,0};
  187. #endif
  188.         
  189.         prn_dialog = pdlg_create(PDLG_3D);
  190.         if (prn_dialog)
  191.         {
  192.             PDLG_SUB    *sub_dialog;
  193.     
  194.             if (in_win)
  195.                 disable_menu();
  196.     
  197.             /* Settings holen */
  198.             prn_settings = load_settings(prn_dialog);
  199.     
  200.             /* Unterdialoge einhängen */
  201.             sub_dialog = create_sub_dialog();
  202.             if (sub_dialog)
  203.                 pdlg_add_sub_dialogs(prn_dialog, sub_dialog);
  204.     
  205.             if (in_win)
  206.             {
  207.                 /* Fenster-Dialog durchführen */
  208.  
  209.                 handle = pdlg_open(prn_dialog, prn_settings, "qed", 0x0000, -1, -1);
  210.  
  211.                 /* ob das wohl erlaubt ist?? :-)) */
  212. #ifdef __MTAES__
  213.                 wind_set_string(handle, WF_NAME, " Drucker-Konfiguration ");
  214. #else
  215.                 wind_set_str(handle, WF_NAME, " Drucker-Konfiguration ");
  216. #endif
  217.                 do
  218.                 {
  219. #ifdef __MTAES__
  220.                     EVNT_multi(MU_KEYBD|MU_MESAG|MU_BUTTON, 2, 1, 1, 
  221.                                     &n, &n, 0L, &ev);
  222. #else
  223.                     ev.mwhich = (short)evnt_multi(MU_KEYBD|MU_MESAG|MU_BUTTON, 2, 1, 1, 
  224.                                                         0, 0, 0, 0, 0,    0, 0, 0, 0, 0,
  225.                                                         (int*)ev.msg, 0, 
  226.                                                         (int*)&ev.mx, (int*)&ev.my, 
  227.                                                         (int*)&ev.mbutton, 
  228.                                                         (int*)&ev.kstate,    (int*)&ev.key, 
  229.                                                         (int*)&ev.mclicks);
  230. #endif
  231.                     if (ev.mwhich & MU_MESAG)
  232.                     {
  233.                         switch (ev.msg[0])
  234.                         {
  235.                             case WM_REDRAW :
  236.                             case WM_MOVED :
  237.                             case WM_SIZED:
  238.                                 if (ev.msg[3] != handle)    /* für fremdes Fenster */
  239.                                 {
  240.                                     handle_mdial_msg((int *)ev.msg);
  241.                                 }
  242.                                 break;
  243.             
  244.                             case WM_BOTTOMED:                    /* nicht erlaubt! */
  245.                                 break;
  246.                             
  247.                             case WM_TOPPED :
  248.                             case WM_NEWTOP :
  249.                             case WM_ONTOP :        
  250.                                 ev.msg[0] = WM_TOPPED;        /* immer Druckerbox toppen! */
  251.                                 ev.msg[3] = handle;
  252.                                 break;
  253.                         }
  254.             
  255.                     }
  256.                     ret = pdlg_evnt(prn_dialog, prn_settings, &ev, &button);
  257.                 } 
  258.                 while (ret == 1);
  259.                 
  260.                 pdlg_close(prn_dialog, &d, &d);
  261.             }
  262.             else
  263.             {
  264.                 /* normalen Dialog durchführen */
  265.                 button = pdlg_do(prn_dialog, prn_settings, "document name", 0x0000);
  266.                 debug("pdlg_do(): %d\n", button);
  267.             }
  268.             
  269.             if (button == PDLG_OK)
  270.                 save_settings(prn_settings);
  271.     
  272.             if (sub_dialog)
  273.             {
  274.                 pdlg_remove_sub_dialogs(prn_dialog);
  275.                 free(sub_dialog);
  276.             }
  277.     
  278.             pdlg_free_settings(prn_settings);
  279.             pdlg_delete(prn_dialog);
  280.     
  281.             if (in_win)
  282.                 enable_menu();
  283.         }
  284.     }
  285.     else
  286.         form_alert( 1, "[1][WDialog ist nicht installiert!][Schade]");
  287. #endif
  288. }
  289.